"use strict";

define("./dist/modules/user/address", [ "router" ], function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function(params) {
        controller.vm = new Vue({
            router: router,
            data: function data() {
                return {
                    user_info: {},
                    publish_text: "确认保存",
                    is_publish: 0
                };
            },
            el: "#pageUserAddress",
            created: function created() {
                this.fetchData();
            },
            methods: {
                fetchData: function fetchData() {
                    var _this = this;
                    var user_info = app.getUserInfo();
                    console.log(user_info);
                    this.user_info = user_info ? user_info : {};
                },
                saveAddress: function saveAddress() {
                    var _this = this;
                    if (_this.is_publish == 1) {
                        return;
                    }
                    app.showLoad();
                    _this.publish_text = "保存中....";
                    _this.is_publish = 1;
                    var data = $("#pageUserAddress").find("form").serializeArray();
                    app.post("api/user/save", data, function(res, textStatus, xhr) {
                        if (res.code != 200) {
                            app.alert(res.msg);
                        } else {
                            //app.getUserInfo("",1);//重新加载个人信息
                            if (res.data) {
                                _this.user_info.name = res.data.name;
                                _this.user_info.phone = res.data.phone;
                                _this.user_info.address = res.data.address;
                                app.setUserInfo(_this.user_info);
                            }
                            // console.log(_this.user_info);
                            app.alert("恭喜你，地址保存成功", function() {
                                _this.$router.go(-1);
                            });
                        }
                        app.hideLoad();
                        _this.is_publish = 0;
                        _this.publish_text = "确认保存";
                    });
                }
            }
        }).$mount("#app");
    };
    module.exports = controller;
});
